var tq = this.getItem('numTotalQty');
var pq = this.getItem('numPsnQty');
if (!tq.isValid() || !pq.isValid()) {
    return;
}

if (tq.getValue() < pq.getValue()) {
    pq.markInvalid('每产出数不超能过总数。');
    return;
}

var me = this;
var scanMsnList = [];
me.getItem('grdInput').getStore().each(function(rcd) {
    scanMsnList.push({
        msn: rcd.get('msn'),
        mo: rcd.get('mo'),
        matCode: rcd.get('matCode'),
        qty: rcd.get('inputQty'),
        carryId: rcd.get('resBarcode')
    });
});

if (Ext.isEmpty(scanMsnList)) {
    Ext.Msg.show({
        title: T.label.save,
        msg: '无投料数据',
        icon: Ext.Msg.ERROR,
        buttons: Ext.Msg.OK
    });
    return;
}

Ext.Msg.show({
    title: T.label.save,
    msg: T.msg.are_you_sure_to_save_data,
    icon: Ext.Msg.QUESTION,
    buttons: Ext.Msg.YESNO,
    fn: function(btnId) {
        if ('yes' == btnId) {
            button.setDisabled(true);

            YX.ZbusRpc.request({
                module: 'SmfrSaveScanMaterialToPsnAndPrintService',
                showSuccess: true,
                params: {
                    printFlag: me.getItem('chkPrint').getValue() ? "Y": "N",
                    totalQty: tq.getValue(),
                    outputQty: pq.getValue(),
                    msnStsList: scanMsnList
                },
                success: function(rsp) {
                    me.getItem('frmScan').getForm().reset();
                    me.loadMoPsnStore({
                        mo: scanMsnList[0].mo
                    });

                    if (me.getItem('chkPrint').getValue() && !Ext.isEmpty(rsp.labelFileName)) {
                        var mainForm = me.getItem('frmMain');
                        Ext.create('Ext.window.Window', {
                            title: '标签打印',
                            height: mainForm.getHeight() - 50,
                            width: mainForm.getWidth() - 200,
                            layout: 'fit',
                            modal: true,
                            frame: false,
                            items: [{
                                html: '<iframe style="width:100%;height:100%" src="export?download=0&fileName=' + rsp.labelFileName + '"/>'
                            }]
                        }).show();

                    }
                },
                callback: function() {
                    button.setDisabled(false);
                }
            });
        }
    }
});